#!/usr/bin/env node

const Koa = require('koa'),
      log = console.log;
const app = new Koa();

app.use(async (ctx, next) => {  // M-logger
  log(`${ctx.method} ${ctx.path}`); 
  let cost = await next();
  //let cost = ctx.response.get('cost');
  log(`cost:${ctx.cost}ms`);
});
app.use((ctx, next) => {
  const start = Date.now();
  next();
  const end = Date.now();
  //ctx.set('cost', end-start);
  
  //return end-start;
  
  ctx.cost = end - start;
})
app.use((ctx, next) => {  //M-hello
  ctx.body = 'hello koa';
});
app.listen(8080);

